package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.Orders;
import com.itheima.domain.R;
import com.itheima.dto.OrdersDto;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //用户下单功能
    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders){
        orderService.submit(orders);
        return R.success("下单成功");
    }

    //历史订单查询
    @GetMapping("/userPage")
    public R findByPage(Integer page,Integer pageSize){
        Page<OrdersDto> list = orderService.findByPage(page,pageSize);
        return R.success(list);
    }

    //订单明细查询
    @GetMapping("/page")
    public R findAll(Integer page,Integer pageSize,String name){
        Page<OrdersDto> lists = orderService.selectByPage(page,pageSize,name);
        return R.success(lists);
    }

    //更改派送状态
    @PutMapping
    public R modify(@RequestBody OrdersDto ordersDto){
        orderService.updateById(ordersDto);
        return R.success("修改成功");
    }
}